Quick Demo

Sachin Yadav , IIT Gandhinagar, sachin.yadav@iitgn.ac.in

IRIS Flower data set ¶

The data set contains information about three species of IRIS flowers namely:

  • Iris setosa
  • Iris versicolor
  • Iris virginica

Four features are collected from each sample, sepal-length, sepal-width, petal-length and petal-width in centi-meters.

InĀ [1]:
# Common imports
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

import plotly.express as px
InĀ [2]:
iris_df = pd.read_csv("./data/IRIS.csv.gz", compression="gzip")
iris_df.sample(5)
Unnamed: 0 sepal_length sepal_width petal_length petal_width species
144 144 6.7 3.3 5.7 2.5 Iris-virginica
48 48 5.3 3.7 1.5 0.2 Iris-setosa
52 52 6.9 3.1 4.9 1.5 Iris-versicolor
23 23 5.1 3.3 1.7 0.5 Iris-setosa
78 78 6.0 2.9 4.5 1.5 Iris-versicolor
InĀ [3]:
fig = px.scatter_3d(iris_df, x='sepal_length', y='sepal_width', z='petal_width',
              color='species', template="plotly_dark")
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()

COVID-19 Dataset ¶

InĀ [4]:
covid_df = pd.read_csv("./data/owid-covid-data.csv.gz", compression="gzip")
covid_df.sample(5)
Unnamed: 0 iso_code continent location date total_cases new_cases new_cases_smoothed total_deaths new_deaths ... female_smokers male_smokers handwashing_facilities hospital_beds_per_thousand life_expectancy human_development_index excess_mortality_cumulative_absolute excess_mortality_cumulative excess_mortality excess_mortality_cumulative_per_million
154914 154914 UKR Europe Ukraine 2020-08-19 98658.0 2005.0 1736.286 2182.0 30.0 ... 13.5 47.4 NaN 8.800 72.06 0.779 NaN NaN NaN NaN
139575 139575 KOR Asia South Korea 2020-11-06 27284.0 89.0 110.429 477.0 1.0 ... 6.2 40.9 NaN 12.270 83.03 0.916 NaN NaN NaN NaN
101362 101362 MNE Europe Montenegro 2020-07-02 616.0 40.0 28.857 12.0 0.0 ... 44.0 47.9 NaN 3.861 76.88 0.829 NaN NaN NaN NaN
95205 95205 MLT Europe Malta 2020-03-05 NaN NaN NaN NaN NaN ... 20.9 30.2 NaN 4.485 82.53 0.895 NaN NaN NaN NaN
133226 133226 SYC Africa Seychelles 2021-12-24 24249.0 0.0 28.857 131.0 0.0 ... 7.1 35.7 NaN 3.600 73.40 0.796 NaN NaN NaN NaN

5 rows Ɨ 68 columns

InĀ [5]:
required_columns = ["iso_code", "location", "continent", "date", "new_cases_smoothed", "total_cases"]
covid_df = covid_df.dropna(subset = required_columns)

covid_df = covid_df.sort_values("date")
InĀ [6]:
covid_df[['iso_code', 'location']].sample(8)
iso_code location
130786 SAU Saudi Arabia
113504 NOR Norway
81105 OWID_KOS Kosovo
82978 LAO Laos
2648 DZA Algeria
72942 IRQ Iraq
106334 NPL Nepal
76316 JAM Jamaica

Covid-19 New Cases Worldwide on 23 December 2021 ¶

InĀ [7]:
covid_day_df = covid_df[covid_df.date == "2021-12-23"]
covid_day_df.sample(5)
Unnamed: 0 iso_code continent location date total_cases new_cases new_cases_smoothed total_deaths new_deaths ... female_smokers male_smokers handwashing_facilities hospital_beds_per_thousand life_expectancy human_development_index excess_mortality_cumulative_absolute excess_mortality_cumulative excess_mortality excess_mortality_cumulative_per_million
76209 76209 ITA Europe Italy 2021-12-23 5517054.0 44585.0 29839.143 136245.0 168.0 ... 19.8 27.8 NaN 3.18 83.51 0.892 NaN NaN NaN NaN
136996 136996 SLB Oceania Solomon Islands 2021-12-23 20.0 0.0 0.000 NaN NaN ... NaN NaN 35.890 1.40 73.00 0.567 NaN NaN NaN NaN
108762 108762 NZL Oceania New Zealand 2021-12-23 13719.0 71.0 57.429 49.0 0.0 ... 14.8 17.2 NaN 2.61 82.29 0.931 NaN NaN NaN NaN
55907 55907 GAB Africa Gabon 2021-12-23 38039.0 0.0 51.143 286.0 0.0 ... NaN NaN NaN 6.30 66.47 0.703 NaN NaN NaN NaN
71009 71009 IDN Asia Indonesia 2021-12-23 4261208.0 136.0 193.000 144042.0 8.0 ... 2.8 76.1 64.204 1.04 71.72 0.718 NaN NaN NaN NaN

5 rows Ɨ 68 columns

InĀ [8]:
fig = px.scatter_geo(covid_day_df, locations="iso_code", color="continent",
                     hover_name="location", size="new_cases_smoothed",
                     projection="natural earth", template="plotly_dark")

fig.show()

Covid-19 Total Cases over the days ¶

InĀ [9]:
fig = px.scatter_geo(covid_df, locations="iso_code", color="continent",
                     hover_name="location", size="total_cases",
                     projection="natural earth", animation_frame="date", template="plotly_dark")

fig.show()

MNIST Dataset ¶

InĀ [10]:
import torchvision
import os

import matplotlib.pyplot as plt
from matplotlib import rc
from matplotlib.animation import FuncAnimation
from matplotlib import animation
InĀ [11]:
rc('animation', html='jshtml')

frn = 10 # Number of frames to process in the animation
fps = 0.5 # Frames per second
mywriter = animation.PillowWriter(fps=fps) 
InĀ [12]:
mnist_dataset = torchvision.datasets.MNIST(root = "data/mnist", train = True, download = True, transform=torchvision.transforms.ToTensor())
InĀ [13]:
fig, ax = plt.subplots(figsize = (10, 10))

def change_plot(frame_idx):
    ax.cla()
    image_tensor = mnist_dataset[frame_idx][0]
    image_tensor_gray = image_tensor[0]
    image_tensor_gray = image_tensor_gray * 255
    ax.matshow(image_tensor_gray, cmap = "gray")
    for i in range(image_tensor_gray.shape[0]):
        for j in range(image_tensor_gray.shape[1]):
            ax.text(i, j, str(int(image_tensor_gray[j][i].item())), va = "center", ha = "center", color = "blue", fontsize = "small")
    ax.axis("off")
    plt.tight_layout()

anim = FuncAnimation(fig, change_plot, frn, interval=1000 / fps)
plt.close()
anim
<Figure size 432x288 with 0 Axes>
InĀ [14]:
mywriter = animation.PillowWriter(fps=fps)

if not os.path.exists("./assets/gif"):
    os.makedir("./assets/gif")
    
anim.save('./assets/gif/mnist.gif',writer=mywriter)
<Figure size 432x288 with 0 Axes>